package com.example.patentback.controller;

import com.example.patentback.entity.Applicant;
import com.example.patentback.service.ApplicantService;
import com.example.patentback.service.PatentApplicantService;
import com.example.patentback.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/applicant")
public class ApplicantController {

    @Autowired
    ApplicantService applicantService;

    @Autowired
    PatentApplicantService patentApplicantService;

    @PostMapping("/add")
    public Result addApplicants(@RequestBody List<Applicant> applicants){
        List<Long> ids = applicantService.addApplicants(applicants);
        return Result.success(ids);
    }

    @PostMapping("/delete")
    public Result deleteApplicants(@RequestBody Long[] applicantIds){
        int i = applicantService.deleteApplicants(applicantIds);
        return Result.success(i);
    }

    @PostMapping("/updateP&A")
    public Result addPatentApplicant(@RequestBody List<Long> allApplicantIds) {
        //更新关联表
        System.out.println(allApplicantIds.size());
        int i = patentApplicantService.updatePatentApplicant(allApplicantIds);
        return Result.success(i);
    }
}
